package com.sky.loveshop.controller;

import com.sky.loveshop.entity.Result;
import com.sky.loveshop.entity.StockChangeHistory;
import com.sky.loveshop.entity.common.PageResult;
import com.sky.loveshop.entity.exception.BizException;
import com.sky.loveshop.entity.exception.BizExceptionEnum;
import com.sky.loveshop.entity.qo.StockChangeHistoryQO;
import com.sky.loveshop.entity.vo.StockChangeHistoryVO;
import com.sky.loveshop.service.StockChangeHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author xcy
 * @version V1.0
 * @description
 * @date 2024/8/18 0:04
 */
@RestController
@RequestMapping("/stockChangeHistory")
public class StockChangeHistoryController {

    @Autowired
    private StockChangeHistoryService stockChangeHistoryService;

    @PostMapping("/listStockChangeHistoryPages")
    public Result<PageResult<StockChangeHistoryVO>> listStockChangeHistoryPages(@RequestBody StockChangeHistoryQO stockChangeHistoryQO) {
        return Result.page(stockChangeHistoryService.listStockChangeHistoryPages(stockChangeHistoryQO));
    }

    @PostMapping("/listStockChangeHistory")
    public Result<List<StockChangeHistoryVO>> listStockChangeHistory(@RequestBody StockChangeHistoryQO stockChangeHistoryQO) {
        return Result.success(stockChangeHistoryService.listStockChangeHistory(stockChangeHistoryQO));
    }

    @PutMapping("/addStockChangeHistory")
    public Result<Integer> addStockChangeHistory(@RequestBody @Valid StockChangeHistory stockChangeHistory) {
        return Result.success(stockChangeHistoryService.addStockChangeHistory(stockChangeHistory));
    }

    @GetMapping("/getStockChangeHistoryById")
    public Result<StockChangeHistoryVO> getStockChangeHistoryById(Integer id) throws BizException {
        if (id == null) {
            throw new BizException(BizExceptionEnum.ID_MUST_NEED);
        }
        return Result.success(stockChangeHistoryService.getStockChangeHistoryById(id));
    }

}
